import {cell, CellGroup, CellBlock, createStore, register} from 'components/form'
import allFilds, {filds, oprateButtons, fildsString} from 'common/filds'
import {getFormConfig} from 'common/form'

export function tabsConfig(row){
  let editting = true
  let formStore = createStore()
  let [data, methods] = getFormConfig(row, formStore)
  formStore = Object.assign(formStore, methods)

  if (!row.id) {
    editting = false
  }

  if (!editting) {
    if (row.collectionName === 'CLOUD-TABLE-MANAGER') {
      data = data.map(it=>{
        if (it.input.type === 'textarea') {
          it.input.value = fildsString
        }
        return it
      })
    }
  }
  
  return {
    $$id: "xxtab",
    tap(e, param, inst){
      const attr = inst.attr();
      const currentIndex = this.currentIndex
      if (currentIndex === 0) {
        if (attr.index !== currentIndex) {
          // save
          formStore.storeHelper.save()
        }
      } else {
        if (attr.index === 0) {
          // restore
          setTimeout(() => {
            formStore.storeHelper.restore()
          }, 100);
        }
      }
    },
    data: [
      // menus
      [
        { title: "基本信息"},
        { title: "正文"},
        { title: "11"}
      ],
  
      // contents
      [
        <CellGroup data={data} store={formStore} />,
        { title: "我是选项二内容啦啦啦！！！！！！" },
        { title: "33333" }
      ]
    ]
  }
}
